<include file="Public/head" />
<link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="/static/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="/static/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="/static/kindeditor/plugins/code/prettify.js"></script>
<script>
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('textarea[name="content1"]', {
            cssPath : '/static/kindeditor/plugins/code/prettify.css',
            uploadJson : '/Article/ueditor',
            allowFileManager : false,
            height:'800px'
        });
        prettyPrint();
    });
</script>
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="clcwht.zxsh" />

    <div class="mianR">
        <h3 class="yonghu">资讯详情-<if condition="$article">编辑<else/>新建</if></h3>
        <div class="newly-build">
            <ul>
                <li><span>标题</span><input type="text" value="{$article.article_title}" id="article_title" class="build-title" /></li>
                <li><span>作者</span><input type="text" value="{$article.author}" id="author" class="build-title" /></li>
                <li><span>所属主频道</span>
                    <select id="category">
                        <option value="0">请选择主频道</option>
                        <volist name="category" id="vo">
                            <option value="{$vo.category_id}" <if condition="$vo['category_id'] eq $article['category_id']">selected="selected"</if>>{$vo.category_title}</option>
                        </volist>
                    </select>
                </li>
                <li><span>所属子频道</span>
                    <select id="child_id">
                        <if condition="!$article">
                            <option value="0">请选择子频道</option>
                            <else/>
                            <volist name="child" id="vo">
                                <option value="{$vo.category_id}" <if condition="$vo['category_id'] eq $article['child_id']">selected="selected"</if>>{$vo.category_title}</option>
                            </volist>
                        </if>
                    </select>
                </li>
                <li><span>推荐精华</span>
                    <select id="is_top">
                        <option value="">请选择是否推荐精华</option>
                        <option value="1" <if condition="$article.is_top eq 1">selected="selected"</if>>是</option>
                        <option value="0" <if condition="$article.is_top eq 0">selected="selected"</if>>否</option>
                    </select>
                </li>
                <if condition="$article.type eq 2">
                    <li><span>来源链接</span>
                        <a target="_blank" style="color:blue;" href="{$article.from_url}">{$article.from_url}</a>
                    </li>
                </if>
                <input type="hidden" id="article_focus" value="{$article.article_focus}" />
                <li class="build-file"><span>焦点图</span><input type="file" /><div class="build-map" id="focus_box"><if condition="$article['article_focus']"><img src="{$article.article_focus}" /><else/>+</if></div>
                    <script type='text/javascript'>
                        new IFrameUploadImg(
                            '浏览'
                            , 'http://' + window.location.host + '/ArticleCrawler/uploadPic'
                            , function (res) {
                                var cdn_url = '{$t|get_content_cdnurl}';
                                if (res.code == 200) {
                                    var head_url = res.data[0];
                                    $('#focus_box').html('<img src="'+cdn_url + head_url+'" />');
                                    $("#article_focus").val(head_url);
                                }
                            });
                    </script>
                </li>
                <input type="hidden" id="article_thumb" value="{$article.article_thumb}" />
                <li class="build-file"><span>缩略图</span><input type="file"><div class="build-map" id="thumb_box"><if condition="$article['article_thumb']"><img src="{$article.article_thumb}" /><else/>+</if></div>
                    <script type='text/javascript'>
                        new IFrameUploadImg(
                            '浏览'
                            , 'http://' + window.location.host + '/ArticleCrawler/uploadPic'
                            , function (res) {
                                var cdn_url = '{$t|get_content_cdnurl}';
                                if (res.code == 200) {
                                    var head_url = res.data[0];
                                    $('#thumb_box').html('<img src="'+cdn_url + head_url+'" />');
                                    $("#article_thumb").val(head_url);
                                }
                            });
                    </script>
                </li>
                <li>
                    <span>发布时间</span>
                    <input type="text" class="build-title" id="publish_time" name="publish_time" value="<if condition="!empty($article['cron_time']) && $article['status'] == 3">{$article.cron_time|date="Y-m-d H:i:s", ###}</if>" readonly="" placeholder="发布时间">
                </li>
                <li>
                    <span>文章简介</span>
                    <textarea id="desc" style="width:300px;height:100px">{$article.article_desc}</textarea>
                </li>
                <li>
                    <span>内容</span>
                    <textarea id="content" name="content1">{$article.article_content}</textarea>
                </li>
            </ul>
        </div>
        <div class="yongBtn">
            <input onclick="saveArticleCrawler({$article.article_id});" type="button" value="保存" class="queding">
            <input type="button" onclick="history.go(-1);" value="取消" class="queding">
        </div>
        <div class="build-alert">
            <h3>确认页面</h3>
            <a href="#">预览web</a>
            <a href="#">预览APP</a>
            <a href="#">直接发布</a>
        </div>
    </div>
    <div class="clear"></div>
    <include file="Public/foot" />
    <script>
        $(function(){
            $('#category').change(function(){
                var category = $(this).val();
                if(category > 0){
                    $.get('/ArticleCrawler/getChildCategory',{category_id:category}, function(data){
                        var html = '<option value="">请选择</option>';

                        for(var i in data){
                            html += "<option value=\""+data[i].category_id+"\">"+data[i].category_title+"</option>";
                        }

                        $('#child_id').html(html);
                    },'json');
                }else{
                    $('#child_id').html('<option value="">子频道</option>');
                }
            });

            $("#publish_time").ymdateplugin({
                showTimePanel: true,
                changeMonth: true,
                changeYear: true,
                gotoCurrent: true,
                minDate: "{$date}"
            });
        });

        function saveArticleCrawler(id){
            editor.sync();
            var title = $('#article_title').val();
            title = title.replace(/<\/?[^>]*>/g,'');
            title = title.replace(/[ | ]*\n/g,'');
            title = title.replace(/\n[\s| | ]*\r/g,'');
            title = title.replace(/ /g,'');
            if(!title){
                shibai_alert('请填写标题');
                return false;
            }
            var author = $('#author').val();
            if(!author){
                shibai_alert('请填写作者');
                return false;
            }
            var category = $('#category').val();
            if(!category){
                shibai_alert('请选择文章分类');
                return false;
            }
            var child = $('#child_id').val();
            if(!child){
                shibai_alert('请选择子分类');
                return false;
            }
            var top = $('#is_top').val();
            var focus = $('#article_focus').val();
            if(!focus){
                shibai_alert('请上传焦点图');
                return false;
            }
            var thumb = $('#article_thumb').val();
            if(!thumb){
                shibai_alert('请上传缩略图');
                return false;
            }
            var desc = $('#desc').val();
            var desc1 = desc.replace(/<\/?[^>]*>/g,'');
            desc1 = desc1.replace(/[ | ]*\n/g,'');
            desc1 = desc1.replace(/\n[\s| | ]*\r/g,'');
            desc1 = desc1.replace(/ /g,'');
            if(!desc){
                shibai_alert('请填写文章简介');
                return false;
            }
            var publish_time = $('#publish_time').val();
            var content = $('#content').val();
            var content1 = content.replace(/<\/?[^>]*>/g,'');
            content1 = content1.replace(/[ | ]*\n/g,'');
            content1 = content1.replace(/\n[\s| | ]*\r/g,'');
            content1 = content1.replace(/ /g,'');
            if(!content1){
                shibai_alert('请填写内容');
                return false;
            }

            $.post('/ArticleCrawler/saveArticleCrawler', {id:id,title:title, author:author, category:category, child:child, top:top, focus:focus, thumb:thumb, desc:desc, content:content, publish_time:publish_time}, function(data){
                if(data.code == '200'){
                    btn_alert(data.msg);
                    window.location = '/ArticleCrawler/index';
                }else{
                    shibai_alert(data.msg);
                }
            },'json');
        }
    </script>